﻿//***********************开发者:赵祥   最后修订时间:2013年5月3日********************************************
$MET.Load.Install(function () {
    ChekPageRight(2005, 4); //验证页面访问权限
    //载入数据报表信息
    $(function () {
        $('#DivShowData').datagrid({
            title: '历史报警数据',
            width: 1,
            height: 1,
            fit: true,
            fitColumns: true,
            singleSelect: true,
            columns: [[
                    { field: 'Loading', title: '载入中', align: 'left' }
                ]],
            pagination: true,
            rownumbers: true,
            pageSize: 20,
            pageList: [20, 40, 60, 80, 100]
        });
        //获取因子列表
        var RTUrl = "../../../../Service/Expand/RealInformation/Alram/AlarmDetail/GetAllAlarmType.ashx";
        var RTData = "";
        $MRT.Ajax(true, RTUrl, RTData, function (xmlData, state) {
            var Json = $MJO.GetObject(xmlData);
            if (Json != null && Json.Successful == true) {
                var options = [];
                options.columns = [];
                options.columns[0] = [];
                for (var I in Json.Data) {
                    var Data = Json.Data[I];
                    options.columns[0].push({ title: Data.TypeName, align: 'center', colspan: 3 });
                }
                options.columns[1] = [];
                for (var I in Json.Data) {
                    var Data = Json.Data[I];
                    //更新时间数值字符串
                    options.columns[1].push($MJO.GetObject("{field: 'T" + Data.No + "PollutantName',title: '污染物',width: 25,align: 'left'}"));
                        //options.columns[1].push($MJO.GetObject("{field: 'T" + Data.No + "Max',title: '最大值',width: 30,align: 'left'"
                        //        + ",formatter: function (value, rowData, rowIndex) {"
                        //        + "var Max = $MCVT.ToDecimal(rowData.T" + Data.No + "Max,2);"
                        //        + "Max = (Max == null ? 0:Max);"
                        //        + "var Title = \"最大值:\" + Max;"
                        //        + "return \"<label title='\" + Title + \"'>\" + Max + \"</label>\";"
                        //        + "}}"));
                        //options.columns[1].push($MJO.GetObject("{field: 'T" + Data.No + "Min',title: '最小值',width: 30,align: 'left'"
                        //        + ",formatter: function (value, rowData, rowIndex) {"
                        //        + "var Min = $MCVT.ToDecimal(rowData.T" + Data.No + "Min,2);"
                        //        + "Min = (Min == null ? 0:Min);"
                        //        + "var Title = \"最小值:\" + Min;"
                        //        + "return \"<label title='\" + Title + \"'>\" + Min + \"</label>\";"
                        //        + "}}"));
                    options.columns[1].push($MJO.GetObject("{field: 'T" + Data.No + "Avg',title: '报警值',width: 30,align: 'left'"
                            + ",formatter: function (value, rowData, rowIndex) {"
                            + "var Avg = $MCVT.ToDecimal(rowData.T" + Data.No + "Avg,2);"
                            + "Avg = (Avg == null ? 0:Avg);"
                            + "var Title = \"平均值:\" + Avg;"
                            + "return \"<label title='\" + Title + \"'>\" + Avg + \"</label>\";"
                            + "}}"));
                    //options.columns[1].push($MJO.GetObject("{field: 'T" + Data.No + "Count',title: '累计值',width: 30,align: 'left'"
                    //        + ",formatter: function (value, rowData, rowIndex) {"
                    //        + "var Count = $MCVT.ToDecimal(rowData.T" + Data.No + "Count,2);"
                    //        + "Count = (Count == null ? 0:Count);"
                    //        + "var Title = \"累计值:\" + Count;"
                    //        + "return \"<label title='\" + Title + \"'>\" + Count + \"</label>\";"
                    //        + "}}"));
                    options.columns[1].push($MJO.GetObject("{field: 'T" + Data.No + "AlarmTime',title: '报警时间',width: 50,align: 'left'"
                            + ", formatter: function (value, rowData, rowIndex) {"
                            + "var GainTime = value;"
                            + "GainTime = (GainTime == null ? 0:$MD.Date(value).toFormatString('yy/mm/dd hh:MM:ss'));"
                            + "var Title = \"获取时间:\" + GainTime;"
                            + "return \"<label title='\" + Title + \"'>\" + GainTime + \"</label>\";"
                            + "}} "));
                }
                $('#DivShowData').datagrid({
                    columns: options.columns
                });
                //载入分页
                var p = $("#DivShowData").datagrid("getPager");
                $(p).pagination({
                    onSelectPage: function (pageNumber, pageSize) {
                        var Grid = $('#DivShowData');
                        var Options = Grid.datagrid('getPager').data("pagination").options;
                        var PageNumber = Options.pageNumber;
                        var PageSize = Options.pageSize;

                        RefreshData($MRT.QueryString("DischargePortNo"), PageNumber - 1, PageSize);
                    }
                });
                //载入分页结束
            }
        });
    });
    var RTUrl = "../../../../Service/Basic/Search/SearchPolluteSourcePort.ashx";
    var RTData = "DischargePortNo=" + $MRT.QueryString("DischargePortNo");
    $MRT.Ajax(true, RTUrl, RTData, function (xmlData) {
        var Json = $MJO.GetObject(xmlData);
        if (Json != null && Json.Successful == true && Json.Data.length > 0) {
            var PolluteSourceName = Json.Data[0].PolluteSourceName;
            var DischargePortName = Json.Data[0].DischargePortName;
            //设置标题信息
            $MEM("LblSignInfo").innerHTML = PolluteSourceName + " [" + DischargePortName + "]";
        }
        //触发搜索事件
        $MEM("BtnRefresh").onclick();
    });

    $MEM("BtnRefresh").onclick = function () {
        var Grid = $('#DivShowData');
        var Options = Grid.datagrid('getPager').data("pagination").options;
        var PageNumber = Options.pageNumber;
        var PageSize = Options.pageSize;

        RefreshData($MRT.QueryString("DischargePortNo"), PageNumber - 1, PageSize);
    }
    
    $MEM("BtnBackPage").onclick = function () {
        $MRT.Back(1);
    }
});

//刷新数据
function RefreshData(DischargePortNo, PageNo, PageSum) {
    //获取数据
    var RTUrl = "../../../../Service/Expand/RealInformation/Alram/AlarmDetail/GetAlarmDetailPaging.ashx";
    var RTData = "DischargePortNo=" + DischargePortNo;
    RTData += "&PageNo=" + PageNo;
    RTData += "&PageSum=" + PageSum;

    $MRT.Ajax(true, RTUrl, RTData, function (xmlData, state) {
        var Json = $MJO.GetObject(xmlData);
        if (Json != null && Json.Successful == true) {
            //获取总记录数
            RTUrl = "../../../../Service/Expand/RealInformation/Alram/AlarmDetail/GetAlarmDetailSum.ashx";
            RTData = "DischargePortNo=" + DischargePortNo;
            $MRT.Ajax(true, RTUrl, RTData, function (innerXmlData) {
                var innerJson = $MJO.GetObject(innerXmlData);
                if (innerJson != null && innerJson.Successful == true) {
                    //填充数据
                    var LoadData = $MJO.GetObject('{ "total": ' + innerJson.Data + ', "rows": [] }');
                    LoadData.rows = Json.Data;
                    //载入数据
                    $('#DivShowData').datagrid('loadData', LoadData);
                    if (Json.Data.length <= 0)
                        $.messager.alert("提示", "无任何相关信息.");
                }
            });
        }
        else {
            $.messager.alert("提示", "无任何相关信息.");
        }
    });
}